package com.example.demo.controller;
import com.example.demo.model.Department;
import com.example.demo.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator 张喜英
 */

    @Api(tags = "department")
    @RestController
    @RequestMapping("/swagger2")
    public class DepartmentController {
        @Autowired
        private IDepartmentService departmentService;
    @CrossOrigin
    @GetMapping("/aaa")
    @ResponseBody
    public List<Department> query(int bmid){
        return departmentService.query(bmid);
    }
    @ApiOperation(value="对部门信息的添加方法")
    @PostMapping("/insertdepartment")
    public int insertDepartment(@RequestBody Department department){
        System.out.println("进入添加部门接口" );
        return departmentService.insertDepartment(department);
    }

    @PostMapping("/getAll")
    public List<Department> getAllDepartment(@RequestBody Department department)
    {
        System.out.println("进入查询方法");
        List<Department> listDepartment=departmentService.getAllDepartment(department);
        return listDepartment;
    }
    @PostMapping("/editDepartment")
    public int EditDepartment(@RequestBody Department department){
        System.out.println("添加修改方法");
        return departmentService.updateDepartment(department);
}
    @GetMapping("/delDepartment")
    public int Delete(int bmid){
        System.out.println("进入删除方法");
        int returnValues=0;
        if(bmid!=0){
            Department department=new Department();
            department.setBmid(bmid);
        returnValues=departmentService.deleteDepartment(department);
        }
        return returnValues;
    }

    @GetMapping("/getOne")
    public Department getDepartment(int bmid){
        Department department=new Department();
        System.out.println("进入单条查询方法");
        if(bmid!=0){
            Department department1=new Department();
            department1.setBmid(bmid);
            department=departmentService.getDepartment(department1);
            System.out.println("返回的数据集合为:"+department.getBmid());
        }
        return department;
    }








}
